package main

import (
	"common/redis"
	"fmt"
	"sync"
	"time"
)

func main() {
	var wait sync.WaitGroup
	//redis.InitRedisCluster([]string{"192.168.0.189:16378", "192.168.0.189:16379", "192.168.0.189:16380"}, "")
	redis.InitRedisPass("192.168.0.240:6379", "")
	fmt.Println("链接成功")
	lock := redis.NewRedisLock()
	go func() {
		wait.Add(1)
		lock.Lock("test")
		fmt.Println("开始执行任务A")
		time.Sleep(10 * time.Second)
		fmt.Println("执行任务A结束")
		lock.UnLock("test")
		wait.Done()
	}()
	lock.Lock("test")
	fmt.Println("开始执行任务B")
	time.Sleep(10 * time.Second)
	fmt.Println("执行任务B结束")
	lock.UnLock("test")
	wait.Wait()
}
